package com.hxs.hxsserver.config;

import com.hxs.hxsserver.config.properties.DozerProperties;
import com.github.dozermapper.core.DozerBeanMapperBuilder;
import com.github.dozermapper.core.Mapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Scope;


/**
 * dozer类转换配置类
 *
 * @author Andi
 */
@Configuration
public class DozerConfig {
    private final DozerProperties dozerProperties;

    @Autowired
    public DozerConfig(DozerProperties dozerProperties) {
        this.dozerProperties = dozerProperties;
    }

    @Bean
    @Scope("singleton")
    public Mapper dozer() {
        String[] mappingFiles = dozerProperties.resolveMappingLocation();
        DozerBeanMapperBuilder builder = DozerBeanMapperBuilder.create();
        if (mappingFiles != null) {
            builder.withMappingFiles(mappingFiles);
        }
        return builder.build();
    }
}
